package com.eling.elcms.cater.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 顾客帐户流水
 * 
 * @author zhoulin
 *
 */
@Entity
@Indexed
@Table(name = "cate_travelaccountflow")
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class) })
public class TravelAccountFlow extends BaseModel {

	private static final long serialVersionUID = 639200644622385042L;

	@Id
	@In
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	private Long pkTravelAccountFlow;

	/** 顾客帐户 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
	@JoinColumn(name = "pkTravelAccount")
	@IndexedEmbedded(depth = 1)
	private TravelAccount travelAccount;

	/** 所属服务点 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkServicePoint")
	@IndexedEmbedded(depth = 1)
	private ServicePoint servicePoint;

	/**充值方式*/
	@Enumerated(EnumType.STRING)
	@In
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private RechargeType rechargeType;
	
	/** 操作人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkUser")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;

	/** 消费类型 */
	@Enumerated(EnumType.STRING)
	@In
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private ConsumeType consumeType;

	/** 消费金额 */
	@Column
	private Double money;

	/** 当前余额 */
	@Column
	private Double balance;

	/** 操作时间 */
	@Column
	@Between
	private Date operateDate;

	/** 备注 */
	@Column(length = 1023)
	private String description;

	@Version
	private Integer version;

	@JsonSerialize(using = EnumSerializer.class)
	public enum RechargeType {
		Cash("现金"), WipeCard("刷卡"), Transfer("转账");
		private String display;

		RechargeType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
	
	@JsonSerialize(using = EnumSerializer.class)
	public enum ConsumeType {
		Recharge("充值"), Consume("消费"), Returned("退卡"), Lose("挂失"), Reissue("补办");
		private String display;

		ConsumeType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkTravelAccountFlow() {
		return pkTravelAccountFlow;
	}

	public void setPkTravelAccountFlow(Long pkTravelAccountFlow) {
		this.pkTravelAccountFlow = pkTravelAccountFlow;
	}

	public TravelAccount getTravelAccount() {
		return travelAccount;
	}

	public void setTravelAccount(TravelAccount travelAccount) {
		this.travelAccount = travelAccount;
	}

	public ServicePoint getServicePoint() {
		return servicePoint;
	}

	public void setServicePoint(ServicePoint servicePoint) {
		this.servicePoint = servicePoint;
	}

	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	public ConsumeType getConsumeType() {
		return consumeType;
	}

	public void setConsumeType(ConsumeType consumeType) {
		this.consumeType = consumeType;
	}

	public Double getMoney() {
		return money;
	}

	public void setMoney(Double money) {
		this.money = money;
	}

	public Double getBalance() {
		return balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	public Date getOperateDate() {
		return operateDate;
	}

	public void setOperateDate(Date operateDate) {
		this.operateDate = operateDate;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public RechargeType getRechargeType() {
		return rechargeType;
	}

	public void setRechargeType(RechargeType rechargeType) {
		this.rechargeType = rechargeType;
	}

}
